#include <iostream>
#include <unordered_map>
#include <string>

class Marathon {
private:
    int start_num;

public:
    Marathon() {
        start_num = 0;
    }

    void get_input() {
        std::unordered_map<std::string, std::string> rec_numbers = {
            {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"}, {"five", "5"}, {"six", "6"},
            {"seven", "7"}, {"eight", "8"}, {"nine", "9"}, {"zero", "0"}
        };

        std::string input;
        std::getline(std::cin, input);
        std::istringstream iss(input);
        std::vector<std::string> input_nums;
        std::string str_num;

        while (iss >> str_num) {
            input_nums.push_back(str_num);
        }

        for (const auto& str_num : input_nums) {
            if (std::isdigit(str_num[0])) {
                std::cout << "Wrong input" << std::endl;
                return;
            }
            if (rec_numbers.find(str_num) == rec_numbers.end()) {
                std::cout << "Wrong input" << std::endl;
                return;
            }
        }

        if (input_nums.size() == 3) {
            int new_num = std::stoi(rec_numbers[input_nums[0]] + rec_numbers[input_nums[1]] + rec_numbers[input_nums[2]]);
            if (std::to_string(new_num).length() != 3) {
                std::cout << "Wrong input" << std::endl;
            } else {
                start_num = new_num;
            }
        } else {
            std::cout << "Wrong input" << std::endl;
        }
    }

    bool is_prime(int a) {
        if (a % 2 == 0) {
            return a == 2;
        }
        int d = 3;
        while (d * d <= a && a % d != 0) {
            d += 2;
        }
        return d * d > a;
    }

    void find_easy_num() {
        if (start_num != 0) {
            if (is_prime(start_num)) {
                std::cout << start_num << std::endl;
            } else {
                int append_id = 0;
                int first_test = 0;

                while (append_id < 100) {
                    append_id++;
                    if (is_prime(append_id + start_num)) {
                        first_test = append_id + start_num;
                        break;
                    }
                }

                append_id = 0;
                int second_test = 0;

                while (append_id < 100) {
                    append_id++;
                    if (is_prime(start_num - append_id)) {
                        second_test = start_num - append_id;
                        break;
                    }
                }

                int check_first = first_test - start_num;
                int check_second = start_num - second_test;

                if (check_second == check_first) {
                    std::cout << std::min(first_test, second_test) << std::endl;
                } else if (check_second > check_first) {
                    std::cout << first_test << std::endl;
                } else if (check_second < check_first) {
                    std::cout << second_test << std::endl;
                }
            }
        }
    }
};

int main() {
    Marathon program;
    program.get_input();
    program.find_easy_num();

    return 0;
}
